﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Rs.Common.Enum;

namespace Rs.Common.WepPost
{
    public class WebPostResult
    {
        /// <summary>
        /// true - 成功,false - 失败
        /// </summary>
        public Boolean Result { get; private set; }
        public byte[] Response { get; private set; }
        public EnumCharsetType CharsetType { get; private set; }
        public String ContentEncoding { get; private set; }
        public HttpWebResponse HttpWebResponse { get; private set; }
        public CookieCollection Cookies { get; private set; }
        public WebPostResult(Boolean Result, byte[] Response, EnumCharsetType CharsetType, String ContentEncoding, HttpWebResponse HttpWebResponse = null)
        {
            this.Result = Result;
            this.ContentEncoding = String.IsNullOrWhiteSpace(ContentEncoding) ? null : ContentEncoding.ToLower().Trim();
            this.Response = HttpHelper.UnZip(Response, this.ContentEncoding);
            this.CharsetType = CharsetType;
            this.HttpWebResponse = HttpWebResponse;
            if (this.HttpWebResponse != null)
            {
                Cookies = this.HttpWebResponse.Cookies;
            }
        }

        public String ResponseToString()
        {
            return Encoding.GetEncoding((Int32)CharsetType).GetString(Response);
        }
    }
}
